/*************************************************************************
 *                                                                       *
 * This file is part of the DogosFrame distribution.  For full copyright *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 *                                                                       *
 *************************************************************************/

#ifndef DOGOS_include_COMMON_tbox_CommandLineParser_h
#define DOGOS_include_COMMON_tbox_CommandLineParser_h

//C++ headers
#include <vector>
#include <string>

namespace DOGOS
{

/**
 * \brief the class get information from command line.
 *
 * for example, when run lslib, one often using the command such as $FreeMAPs -f file_name
 * or $ mpirun -n 2 FreeMAPs -f file_name
 * now the rational command is $FreeMAPs [option] parameter
 */
class CommandLineParser
{
public:

    /**
     * \brief constructor function using command parameter as input information.
     *
     *  @param[in] argc the number of parameters input from command line
     *  @param[in] argv the parameters input from command
     *
     *
     * the argv information will be saved in _command in order. so that one can use the information convenient
     */
    CommandLineParser(
        int argc,
        char** argv);

    /**
     * destructor function
     */
    virtual
    ~CommandLineParser();

public:

    /**
     * \brief indicate whether a option of quested is existed in the command
     *
     * @param[in] option the option to be checked.
     * @return true if it exists and false otherwise.
     */
    bool
    has_option (
        const std::string& option) const;

    /**
     * \brief return the parameter after the specified option.
     * @param[in] option the option that the parameter followed
     * @return the parameter following the option
     *
     * if no option exist, then return a string of empty.
     *
     * for example, if one use the command "FreeMAPs -f /home/input.dat", then get_parameter("-f")="/home/input.dat"
     */
    std::string
    get_parameter(
        const std::string& option) const;

private:

    /*
     * the string in the argv, saved in order.
     */
    std::vector<std::string> d_commands;
};

}

#include "COMMON/tbox/CommandLineParser.inl"

#endif
